package com.yfp.client.controller;


import com.yfp.client.domain.dto.ShoppingCartsDto;
import com.yfp.client.domain.vo.ShoppingCartsVo;
import com.yfp.client.service.ShoppingCartsService;
import com.yfp.client.util.Response;
import com.yfp.client.util.SecurityUtils;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 购物车表(ShoppingCarts)表控制层
 *
 * @author makejava
 * @since 2024-05-24 17:31:28
 */
@RestController
@RequestMapping("/client/shoppingCarts")
@Tag(name = "客户端购物车")
public class ShoppingCartsController {

    /**
     * 客户端购物车对象
     */
    @Resource
    private ShoppingCartsService shoppingCartsService;

    @GetMapping
    @Operation(summary = "查询购物车")
    public Response<List<ShoppingCartsVo>> findClientShoppingCarts(Long machineId) {
        return Response.success(this.shoppingCartsService.findClientShoppingCarts(machineId));
    }

    @PutMapping
    @Operation(summary = "新增或修改购物车")
    public Response<Void> update(@RequestBody ShoppingCartsDto shoppingCartsDto) {
        this.shoppingCartsService.updateShoppingCarts(shoppingCartsDto);
        return Response.success();
    }

    @DeleteMapping("/all")
    @Operation(summary = "清空购物车-所有商品", description = "清空购物车-所有商品")
    public Response<Void> deleteShoppingCartsALL(String machineId) {
        this.shoppingCartsService.deleteByUserIdAndMachineId(SecurityUtils.getClientId(), machineId);
        return Response.success();
    }
}

